package cn.zktr.Personnel.model.service.tanyali;



import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;

import cn.zktr.Personnel.model.dao.tanyali.EmaAgtDao;
import cn.zktr.Personnel.model.dao.tanyali.EmaFebDao;
import cn.zktr.Personnel.model.dao.tanyali.EmaOutDao;
import cn.zktr.Personnel.model.dao.tanyali.EmaZkzDao;
import cn.zktr.Personnel.model.mappers.tanyali.EmaAgtMapper;
import cn.zktr.Personnel.model.pojos.PerEmaAgt;
import cn.zktr.Personnel.model.pojos.PerEmaFeb;
import cn.zktr.Personnel.model.pojos.PerEmaOut;
import cn.zktr.Personnel.model.pojos.PerEmaZkz;
/**
 * @author lenovo
 *
 */
/**
 * @author lenovo
 *
 */
@Service
@Transactional(rollbackOn=Exception.class)
public class EmaAgtService {
	
	
	
	@Autowired
	private EmaAgtDao agtdao;	
	
	@Autowired
	private EmaFebDao febdao;	
	
	@Autowired
	private EmaOutDao outdao;	
	
	@Autowired
	private EmaAgtMapper agtmer;

	@Autowired
	private EmaZkzDao zkzdao;	
	
	

	
	/**
	 * @param febid
	 * @return  根据id查询信息反馈表
	 */
	public PerEmaFeb findByFebId(Integer febid) {
		return febdao.findById(febid).get();
		
	}
	
	/**
	 * @param outid
	 * @return 根据id查询考试试卷
	 */
	public PerEmaOut findByOutId(Integer outid) {
		return outdao.findById(outid).get();
		
	}
	
	
	
	/**
	 * 招聘考试安排
	 */
	public Iterable<PerEmaAgt> selectAgtAll(){
		return agtdao.findAll();
	}
	
	/**考试安排更新
	 * @param agt
	 */
	public void updateAgt(PerEmaAgt agt) {
		agtdao.save(agt);
	}
	
	/**
	 *return 查询所有招聘考试安排
	 */
	public JSONArray zpanpaiselect() {
		return agtmer.zpanpaiselect();
		
	}
	
	/**
	 *return 招聘考试新增
	 */
	public JSONArray zpapxingzengselect() {
		return agtmer.zpanpaixzselect();
	}
	
	/**
	 * @return 招聘查询数据模糊查询
	 */
	public JSONArray zpanpaichaxun(String rsename) {
		return agtmer.zpanpaichaxun("%"+rsename+"%");
	}
	
	
	/**培训安排 新增
	 * @return
	 */
	public JSONArray pxanpaixzselect() {
		return agtmer.pxanpaixzselect();
		
	}
	
	/**
	 *return 培训考试新增
	 */
	public JSONArray pxapxingzengselect() {
		return agtmer.pxanpaiselect();
	}

	/**
	 * @return 培训查询数据模糊查询
	 */
	public JSONArray pxanpaichaxun(String empname) {
		return agtmer.pxanpaichaxun("%"+empname+"%");
	}
	
	/**
	 *return 查询所有培训考试安排
	 */
	public JSONArray pxanpaiselect() {
		return agtmer.pxanpaiselect();
		
	}
	
	/**升职安排 新增
	 * @return
	 */
	public JSONArray szanpaixzselect() {
		return agtmer.szanpaixzselect();
		
	}
	
	/**
	 *return 查询所有升职考试安排
	 */
	public JSONArray szanpaiselect() {
		return agtmer.szanpaiselect();
		
	}
	/**
	 *return 升职考试新增
	 */
	public JSONArray szapxingzengselect() {
		return agtmer.szanpaiselect();
	}

	
	/**
	 * @return 升职查询数据模糊查询
	 */
	public JSONArray szanpaichaxun(String empname) {
		return agtmer.szanpaichaxun("%"+empname+"%");
	}
	/**
	 * @return 信息反馈数据
	 */
	public JSONArray xinxifankuiselect() {
		// TODO Auto-generated method stub
		return agtmer.xinxifankui();
	}
	
	public void addZKZ(String zhunkaozheng) {
		PerEmaZkz zkz = new PerEmaZkz();
		zkz.setZkzrem(zhunkaozheng);
		zkzdao.save(zkz);
	}
	

	public void updat_feb(Integer febid,String zhunkaozheng, String kaikao, String jieshu, Integer shichang, String didian) {
		PerEmaFeb feb = febdao.findById(febid).get();
		feb.setPerEmaZkz(zkzdao.findByZkzrem(zhunkaozheng));
		
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Timestamp ts1 = new Timestamp(format.parse(kaikao).getTime());
			Timestamp ts2 = new Timestamp(format.parse(jieshu).getTime());
			feb.setFebmintime(ts1);
			feb.setFebmaxtime(ts2);
			feb.setFebstat("-1");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		feb.setJuldz(didian);
		feb.setFebsc(shichang);

		febdao.save(feb);
	}

	public JSONArray zhunkaozhengpaichong(String zhunkaozheng) {
		return agtmer.zhunkaozhengpaichong(zhunkaozheng);
		// TODO Auto-generated method stub
		
	}
	
	
	
	
}